home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Add-Ons / MicroPhone / Open Mike™ / Open Mike™ 012 / Mike's Folder / Tips & Tricks < prev    next >
Encoding:
Text File  |  1993-12-01  |  4.6 KB  |  80 lines  |  [TEXT/ttxt]

  1. Tips & Tricks
  2. =============
  3. Copyright © 1993 by Celestin Company
  4. All rights reserved.
  5.  
  6. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without permission in writing from the publisher. However, you are permitted to make copies of this work, printed or otherwise, as long as said copies are for your personal use only.
  7.  
  8. Introduction
  9. ------------
  10. If you've got a tip or a trick that you think would benefit other Open Mike readers, please share it with us. Readers whose tip or trick we use will receive a free issue of Open Mike. Such a deal!
  11.  
  12. A reader asks us how to deal with a particularly hairy situation, so we'll dedicate this column to tackling the problem.
  13.  
  14. The question is, how do you find out the name of a file that you've just downloaded? Though we wish that MicroPhone had some sort of built-in way of getting around this problem, it's something that can be done from scripting. So, here is an answer of sorts.
  15.  
  16. The basis of finding out the name of the file that was just downloaded is simple. First, take a snapshot of the world before the download. Then, take a snapshot after the download. Compare the two snapshots and the difference will be the new file. Simple enough, right?
  17.  
  18.  Set Variable fname from Expression "''"
  19.  Set Variable one_dir from Expression "GetDir(ReceivePath,false)"
  20.  Receive File ZMODEM MacBinary "'dummy name'"
  21.  Set Variable two_dir from Expression "GetDir(ReceivePath,false)"
  22.  Set Variable c from Expression "0"
  23.  Set Variable m from Expression "IndexMax(two_dir)"
  24.  While Expression "c < m"
  25.    Set Variable c from Expression "c + 1"
  26.    If Expression "one_dir[c] <> two_dir[c]"
  27.      Remark "--- this must be the file!"
  28.      Set Variable fname from Expression "two_dir[c]"
  29.      Set Variable c from Expression "m"
  30.    End If
  31.  End While
  32.  If Expression "Length(fname) > 0"
  33.    Alert OK "'The downloaded file is called ' & fname & '.'"
  34.  End If
  35.  
  36. In order to find out where the file is going to be downloaded, use the ReceivePath function. This will tell you the directory into which the file will go. Grab a list of files in this directory and store it in a variable. Then, go ahead with the file transfer. After the file transfer, grab a new list of files in this directory. Now, all you have to do is compare the directory contents one-by-one until you don't get a match. When this happens, you know that you have the name of the new file.
  37.  
  38. There is one problem with the above script: What if the user has downloaded a batch of files? It's only going to return the name of the first different file it finds. What do we do in a situation like this? The best way to deal with this situation is to not assume that only one file is going to be different. Instead, build a third list of files, ones that do not exist in both the first and second lists. This is easier than it sounds. Take a look at the following lists:
  39.  
  40.   Banana                Banana
  41.   Cherry                Cherry
  42.   Grapefruit            Doughnut
  43.   Pineapple             Grapefruit
  44.                         Jackelope
  45.                         Pineapple
  46.  
  47. What you want to do is create a third list that only contains:
  48.  
  49. Doughnut
  50. Jackelope
  51.  
  52. So, the sixty eight thousand dollar question is, how do you generate this list? The answer to the sixty eight thousand dollar question is, rewrite the above script to accomodate such a situation. You need to create a loop within a loop, and for every element in the second list, check it against each element in the first list. If there is no match, write the element to a third list.
  53.  
  54.  Delete Variable fnames
  55.  Set Variable one_dir from Expression "GetDir(ReceivePath,false)"
  56.  Receive File ZMODEM MacBinary "'dummy name'"
  57.  Set Variable two_dir from Expression "GetDir(ReceivePath,false)"
  58.  Set Variable c from Expression "0"
  59.  Set Variable m from Expression "IndexMax(two_dir)"
  60.  While Expression "c < m"
  61.    Set Variable c from Expression "c + 1"
  62.    Set Variable x from Expression "0"
  63.    Set Variable y from Expression "IndexMax(one_dir)"
  64.    Set Variable match from Expression "false"
  65.    While Expression "x < y"
  66.      Set Variable x from Expression "x + 1"
  67.      If Expression "two_dir[c] = one_dir[x]"
  68.        Remark "--- this is an old file"
  69.        Set Variable match from Expression "true"
  70.      End If
  71.    End While
  72.    If Expression "not match"
  73.      Remark "--- this must be a new file"
  74.      Set Variable z from Expression "IndexMax(fnames) + 1"
  75.      Set Variable fnames[z] from Expression "two_dir[c]"
  76.    End If
  77.  End While
  78.  If Expression "IndexMax(fnames) > 0"
  79.    Set Variable temp from Expression "ChooseOne(fnames,'New Files:','OK')"
  80.  End If